<style>
.affix{top:10px;}
.head-style-list li,.editor-template-list li{cursor: pointer;}
</style>
		<div class="ui-portlet">
			{{template wxes/_user_wxes}}
			<ol class="breadcrumb">
			  <li><a href="/users/index"><i class="fa fa-home"></i>&nbsp;&nbsp;个人中心</a></li>
			  <li class="active">编辑优惠回答</li>
			</ol>
		</div>           
       <hr>

{{$this->Form->create('WxPromotion',array('class'=>'form-horizontal','role'=>'form'))}}
	<ul class="nav nav-tabs"  role="tablist">
    	<li role="presentation" class="active"><a href="#chi-info" aria-controls="home" role="tab" data-toggle="tab">中文</a></li>
    	<li role="presentation"><a href="#eng-info" aria-controls="home" role="tab" data-toggle="tab">英文</a></li>
		<li></li>
	</ul>
	
	<div class="tab-content">
		
		<div role="tabpanel" class="tab-pane active" id="chi-info">
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxPromotionName">活动标题</label>
				<div class="col-sm-9 controls">
					{{$this->Form->hidden('id')}}
					{{$this->Form->hidden('locale',array('value'=>'zh_cn'))}}
					{{$this->Form->input('name',array('class'=>'form-control','div'=>false,'label'=>false))}}
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxPromotionCateId">活动所属分类</label>
				<div class="col-sm-9 controls select">
					{{$this->Form->input('cate_id',array('class'=>'form-control','div'=>false,'label'=>false))}}
					<p><a href="{{$this->Html->url(array('controller'=>'user_cates','action'=>'add','WxPromotion'))}}">新增优惠活动分类</a></p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxPromotionCoverimg">封面图片</label>
				<div class="col-sm-9 controls select">
					{{$this->Swfupload->load('coverimg',array(
					'label'=>false,'modelClass'=>'WxPromotion',
					'no_db'=>1,'upload_limit'=>1,
					'file_types'=> '*.jpg;*.gif;*.png;*.bmp',
					'isadmin'=>false
					))}}
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxPromotionMsgType">活动时间</label>
				<div class="col-sm-9 controls form-inline">
					{{$this->Form->input('start_time',array('class'=>'form-control','type'=>'text','div'=>false,'label'=>false,'style'=>'width:120px'))}} ~
					{{$this->Form->input('end_time',array('class'=>'form-control','type'=>'text','div'=>false,'label'=>false,'style'=>'width:120px'))}}
				</div>
			</div>	
			<div class="form-group" id="divWxPromotionSummary">
				<label class="col-sm-2 control-label" for="WxPromotionSummary">活动摘要</label>
				<div class="col-sm-9 controls">
					{{$this->Form->input('summary',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3'))}}
				</div>
			</div>
			
			<div class="form-group" id="divWxPromotionUrl">
				<label class="col-sm-2 control-label" for="WxPromotionUrl">活动详情</label>
				<div class="col-sm-12 controls">
					{{$this->Form->input('content',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3'))}}
				</div>
			</div>
			
			<div class="form-group" id="divWxPromotionSummary">
				<label class="col-sm-2 control-label" for="WxPromotionSummary">解释说明</label>
				<div class="col-sm-9 controls">
					{{$this->Form->input('explain',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3'))}}
				</div>
			</div>
		</div>
		<div role="tabpanel" class="tab-pane" id="eng-info">
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxPromotionI18nName">活动标题</label>
				<div class="col-sm-9 controls">
					{{$this->Form->hidden('WxPromotionI18n.en_us.id')}}
					{{$this->Form->input('WxPromotionI18n.en_us.name',array('class'=>'form-control','div'=>false,'label'=>false))}}
				</div>
			</div>
			<div class="form-group" id="divWxPromotionSummary">
				<label class="col-sm-2 control-label" for="WxPromotionI18nSummary">活动摘要</label>
				<div class="col-sm-9 controls">
					{{$this->Form->input('WxPromotionI18n.en_us.summary',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3'))}}
				</div>
			</div>
			
			<div class="form-group" id="divWxPromotionUrl">
				<label class="col-sm-2 control-label" for="WxPromotionI18nContent">活动详情</label>
				<div class="col-sm-12 controls">
					{{$this->Form->input('WxPromotionI18n.en_us.content',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3'))}}
				</div>
			</div>
			<div class="form-group" id="divWxPromotionSummary">
				<label class="col-sm-2 control-label" for="WxPromotionI18nExplain">解释说明</label>
				<div class="col-sm-9 controls">
					{{$this->Form->input('WxPromotionI18n.en_us.explain',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3'))}}
				</div>
			</div>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-2 control-label"></label>
		<div class="col-sm-9"><input class="btn btn-primary" type="submit" value="提交"></div>
	</div>
{{$this->Form->end()}}

{{$this->Html->script(array(
	'ckeditor/ckeditor.js',
	'swfupload/swfupload.js',
	'swfupload/swfupload.queue.js',
	'swfupload/swfupload.cookies.js',
	'swfupload/fileprogress.js',
	'swfupload/handlers.js',
))}}

<script>

var current_ckeditor_instance = null;

$(function(){
	$('#left-side-affix').width($('#left-sidebar').width());

	CKEDITOR.editorConfig = function( config ){
		config.toolbar = 'FRONT';
	}
	ckeditors['WxPromotionContent'] = CKEDITOR.replace( 'WxPromotionContent',
		    {
		        customConfig : '{{$this->Html->url("/js/ckeditor/front-config.js")}}'
		    });
	ckeditors['WxPromotionContent'].on('focus',function(e){
		current_ckeditor_instance = e.editor;
	});
	
	ckeditors['WxPromotionI18nEnUsContent'] = CKEDITOR.replace( 'WxPromotionI18nEnUsContent',
		    {
		        customConfig : '{{$this->Html->url("/js/ckeditor/front-config.js")}}'
		    });
	ckeditors['WxPromotionI18nEnUsContent'].on('focus',function(e){
		current_ckeditor_instance = e.editor;
	});
	

	/*CKEDITOR.on( 'instanceReady', function( e ){
		e.editor.document.appendStyleSheet( '{{$this->Html->url("/stylevars/getcss.css")}}' );
		e.editor.document.appendStyleSheet( '{{$this->Html->url("/css/ui-customer.css")}}' );
		//e.editor.setMode( 'source' );
		e.editor.on( 'mode', function( e ){
			if(e.editor.mode == 'wysiwyg'){
				e.editor.document.appendStyleSheet( '{{$this->Html->url("/stylevars/getcss.css")}}' );
				e.editor.document.appendStyleSheet( '{{$this->Html->url("/css/ui-customer.css")}}' );
			}
		});
		//if($('.cke_top').parent('ui-dialog-content').size()<1){
		//	$('.cke_top').addClass('clearfix').affix();
		//}
	});*/


	$('.head-style-list li').click(function(){
		var styles = $(this).data('style');
		//alert(style_str)
		//var styles = jQuery.parseJSON(style_str);
		set_style('h1,h2,h3,h4,h5,h6',styles);

	});

	$('.editor-template-list li').click(function(){
		insertHtml($(this).html());
	})

});

function insertHtml(html){
	if(current_ckeditor_instance){
		var oEditor = current_ckeditor_instance;
		// Check the active editing mode.
		if (oEditor.mode == 'wysiwyg' ){
			// Insert the desired HTML.
			oEditor.insertHtml(html);
		}
		else{
			alert($.jslanguage.wysiswyg_mode );
		}
	}
	else{	
		alert($.jslanguage.select_editor);
	}	
}

function set_style(selector,styles){
	//ckeditors['WxPromotionContent'].focus();
	//ckeditors['WxPromotionContent'].execCommand('selectAll');

	var html = ckeditors['WxPromotionContent'].getData();
	
	var obj = $('<div id="editor-content">'+html+"</div>");
	obj.find(selector).each(function(){
		$(this).css(styles);
	});
	ckeditors['WxPromotionContent'].setData(obj.html());

}
</script>